import { defineStore } from 'pinia'
import tang300 from "../assets/tang300.json";
import * as OpenCC from "opencc-js";

const converter = OpenCC.Converter({ from: "hk", to: "cn" });
const tang300Str = converter(JSON.stringify(tang300));
const tang300List = JSON.parse(tang300Str);
const random = Math.floor(Math.random() * (366 - 1 + 1)) + 1;

export const useTang300Store = defineStore("TANG300", {
  state() {
    return {
      defaultId: tang300List[random].id,
      inputContent: '',
      tang300List: tang300List,
    }
  },
  getters: {
    titleAuthorList: (state) => {
      return state.tang300List.map(item => {
        return {
          id: item.id,
          title: `${item.title}(${item.author})`,
        }
      })
    }
  },
  actions: {
    getParagraphs() {
      return this.tang300List.find(item => item.id === this.defaultId)
    }
  }
})